import operate from '@dfeidao/atom-nodejs/db/operate';
import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';
import { IncomingHttpHeaders } from 'http';
// tslint:disable-next-line: ordered-imports
import { systemid } from '../../atom/config';

interface Message {
	filter: {
		topic_type: string;
		topic: string;
		option_a: string;
		option_b: string;
		option_c: string;
		option_d: string;
		right_answer: string;
		productid: string;
		question_bank_type: string;
	};
	// cookie: {
	// 	uk: string;
	// 	[key: string]: string
	// };
	// urls: {
	// 	base: string;
	// 	origin: string;
	// 	url: string;
	// };
	// query: {};
	// params: {};
	// headers: {};
	// captcha: string;
}


export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	const r=await doc_code(action_id, session_id, systemid,'BM0016461','',1);
	const { exec, insert} = operate(action_id, session_id, systemid);
	// 插入数据
	insert('question_bank', {
		productid:message.filter.productid,
		topic_type:message.filter.topic_type,
		topic:message.filter.topic,
		option_a:message.filter.option_a,
		option_b:message.filter.option_b,
		option_c:message.filter.option_c,
		option_d:message.filter.option_d,
		right_answer:message.filter.right_answer,
		question_bank_type:message.filter.question_bank_type,
		question_no:r.result
	});
	const res = await exec();
	return res;
}
